package com.south.base.test;

import org.junit.Test;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.List;

/**
 * @author Administrator
 * @date 2020/3/30 16:49
 */
public class InitIndia {
    public static final String INTEGER = "Integer";
    public static final String DATE = "Date";
    public static final String DOUBLE = "Double";
    private List<String[]> columns = Arrays.asList(
            new String[]{"numIntervalLatest","",INTEGER},
            new String[]{"numIntervalLatestToEarliest","",INTEGER},
            new String[]{"numEmptySms60","",INTEGER},
            new String[]{"numEmptySmsFor7Day60","",INTEGER},
            new String[]{"numIncomeBalGtRs100","",DOUBLE},
            new String[]{"numLatestBal","",DOUBLE},
            new String[]{"numLatestBal2","",DOUBLE},
            new String[]{"numIntervalLatestBal","",INTEGER},
            new String[]{"numIncomeGt100Rs","",INTEGER},
            new String[]{"numIncomeGt100Rs1","",INTEGER},
            new String[]{"numIncomeGt100Rs2","",INTEGER},
            new String[]{"numIncomeGt100Rs3","",INTEGER},
            new String[]{"numIncomeGt100Rs4","",INTEGER},
            new String[]{"numIncomeLt100Rs","",INTEGER},
            new String[]{"numIncomeLt100Rs1","",INTEGER},
            new String[]{"numIncomeLt100Rs2","",INTEGER},
            new String[]{"numIncomeLt100Rs3","",INTEGER},
            new String[]{"numIncomeLt100Rs4","",INTEGER},
            new String[]{"numIncomeGt10000Rs","",INTEGER},
            new String[]{"numIncomeGt10000Rs1","",INTEGER},
            new String[]{"numIncomeGt10000Rs2","",INTEGER},
            new String[]{"numIncomeGt10000Rs3","",INTEGER},
            new String[]{"numIncomeGt10000Rs4","",INTEGER},
            new String[]{"numIncomeGt100RsMoney","",DOUBLE},
            new String[]{"numIncomeGt100RsMoney1","",DOUBLE},
            new String[]{"numIncomeGt100RsMoney2","",DOUBLE},
            new String[]{"numIncomeGt100RsMoney3","",DOUBLE},
            new String[]{"numIncomeGt100RsMoney4","",DOUBLE},
            new String[]{"numIncomeGt100RsBalAvg","",DOUBLE},
            new String[]{"numIncomeGt100RsBalAvg1","",DOUBLE},
            new String[]{"numIncomeGt100RsBalAvg2","",DOUBLE},
            new String[]{"numIncomeGt100RsBalAvg3","",DOUBLE},
            new String[]{"numIncomeGt100RsBalAvg4","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneyAvg","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneyAvg1","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneyAvg2","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneyAvg3","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneyAvg4","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneyMax","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneyMax1","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneyMax2","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneyMax3","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneyMax4","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneySqrt","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneySqrt1","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneySqrt2","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneySqrt3","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneySqrt4","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneyRange","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneyRange1","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneyRange2","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneyRange3","",DOUBLE},
            new String[]{"numIncomeGt100RsMoneyRange4","",DOUBLE},
            new String[]{"numIntervalAvg30","",DOUBLE},
            new String[]{"numIntervalAvg60","",DOUBLE},
            new String[]{"numIntervalAvg90","",DOUBLE},
            new String[]{"numIncomeGt100RsFrequency1","",INTEGER},
            new String[]{"numIncomeGt100RsFrequency2","",INTEGER},
            new String[]{"numIncomeGt100RsFrequency3","",INTEGER},
            new String[]{"numIncomeMoneyFrequency1","",DOUBLE},
            new String[]{"numIncomeMoneyFrequency2","",DOUBLE},
            new String[]{"numIncomeMoneyFrequency3","",DOUBLE},
            new String[]{"numIncomeMoneyGrowth1","",DOUBLE},
            new String[]{"numIncomeMoneyGrowth2","",DOUBLE},
            new String[]{"numIncomeMoneyGrowth3","",DOUBLE}
    );
    private String tableName = "riskt_indicator_sms_income";
    private String tableDesc = "短信收入信息指标表";

    @Test
    public void javaFile() {
        for (String[] column : columns) {
            System.out.println("/**" + column[1] + "*/private " + column[2] + " " + underline2Hump(column[0]) + ";");
        }
    }

    @Test
    public void createTable() {
        System.out.println("CREATE TABLE " + tableName + " (\n" +
                "\t`id` BIGINT ( 20 ) NOT NULL AUTO_INCREMENT COMMENT '主键',\n" +
                "\t`consumer_no` VARCHAR ( 20 ) NULL DEFAULT NULL COMMENT '用户ID',\n" +
                "\t`order_no` VARCHAR ( 40 ) NULL DEFAULT NULL COMMENT '借款ID',\n" +
                "\t`create_time` datetime ( 0 ) NULL DEFAULT CURRENT_TIMESTAMP ( 0 ) COMMENT '创建时间',\n" +
                "\t`update_time` datetime ( 0 ) NULL DEFAULT CURRENT_TIMESTAMP ( 0 ) ON UPDATE CURRENT_TIMESTAMP ( 0 ) COMMENT '更新时间',");
        for (String[] column : columns) {
            if (INTEGER.equals(column[2])) {
                System.out.println("\t`" + humpToUnderline(column[0]) + "` int(4) NULL DEFAULT 0 COMMENT '" + column[1] + "',");
            } else if (DOUBLE.equals(column[2])) {
                System.out.println("\t`" + humpToUnderline(column[0]) + "` DECIMAL(10,2) NULL DEFAULT 0 COMMENT '" + column[1] + "',");
            } else if (DATE.equals(column[2])) {
                System.out.println("\t`" + humpToUnderline(column[0]) + "` datetime ( 0 ) NULL COMMENT '" + column[1] + "',");
            }
        }
        System.out.println("\tPRIMARY KEY ( `id` ) USING BTREE,\n" +
                "\tINDEX `idx_consumer_no` ( `consumer_no` ) USING BTREE,\n" +
                "\tINDEX `idx_order_no` ( `order_no` ) USING BTREE \n" +
                ") COMMENT = '" + tableDesc + "';");
    }

    @Test
    public void mapper() {
        for (String[] column : columns) {
            if (INTEGER.equals(column[2])) {
                System.out.println("<if test=\"" + underline2Hump(column[0]) + " != null \">\n" +
                        "    " + humpToUnderline(column[0]) + " = #{" + underline2Hump(column[0]) + ",jdbcType=INTEGER},\n" +
                        "</if>");
            } else if (DOUBLE.equals(column[2])) {
                System.out.println("<if test=\"" + underline2Hump(column[0]) + " != null \">\n" +
                        "    " + humpToUnderline(column[0]) + " = #{" + underline2Hump(column[0]) + ",jdbcType=DECIMAL},\n" +
                        "</if>");
            } else if (DATE.equals(column[2])) {
                System.out.println("<if test=\"" + underline2Hump(column[0]) + " != null \">\n" +
                        "    " + humpToUnderline(column[0]) + " = #{" + underline2Hump(column[0]) + ",jdbcType=TIMESTAMP},\n" +
                        "</if>");
            }
        }

    }

    @Test
    public void java2Columns() {
        for (Field field : JavaFile.class.getDeclaredFields()) {
            if (!Modifier.isStatic(field.getModifiers())) {
                System.out.println("new String[]{\""+field.getName()+"\",\"\","+field.getType().getSimpleName().toUpperCase()+"},");
            }
        }

    }

    public static String humpToUnderline(String para) {
        StringBuilder sb = new StringBuilder(para);
        int temp = 0;//定位
        for (int i = 0; i < para.length(); i++) {
            if (Character.isUpperCase(para.charAt(i))) {
                sb.insert(i + temp, "_");
                temp += 1;
            }
        }
        return sb.toString().toLowerCase();
    }

    public static String underline2Hump(String para) {
        StringBuilder sb = new StringBuilder(para);
        for (int i = 0; i < sb.length(); i++) {
            if (sb.charAt(i) == '_') {
                sb.deleteCharAt(i);
                sb.replace(i, i + 1, String.valueOf(Character.toUpperCase(sb.charAt(i))));
                i--;
            }
        }
        return sb.toString();
    }

    private class JavaFile {
        private static final long serialVersionUID = 7336105690654263742L;
        /**
         * 最近一条短信时间距今天数差
         */
        private Integer numIntervalLatest;
        /**
         * 最近一条短信时间和最早一条短信时间的天数差
         */
        private Integer numIntervalLatestToEarliest;
        /**
         * 最近60天没有短信记录的天数
         */
        private Integer numEmptySms60;
        /**
         * 最近60天连续7天没有短信记录的次数
         */
        private Integer numEmptySmsFor7Day60;
        /**
         * 最近一条银行卡入账短信的金额（不会为空）（只统计大于100卢比）
         */
        private Double numIncomeBalGtRs100;
        /**
         * 最近一条银行卡入账短信的余额（取不到则为null，取得到的话值=最近一条可取到的银行卡入账短信的余额）
         */
        private Double numLatestBal;
        /**
         * 最近一条可取到的银行卡入账短信的余额（仍取不到则为null）
         */
        private Double numLatestBal2;
        /**
         * 最近一条银行卡入账短信的距今天数差
         */
        private Integer numIntervalLatestBal;
        /**
         * n月（申请当月）银行卡入账短信笔数（只统计大于100卢比）
         */
        private Integer numIncomeGt100Rs;
        /**
         * n-1月银行卡入账短信笔数
         */
        private Integer numIncomeGt100Rs1;
        /**
         * n-2月银行卡入账短信笔数
         */
        private Integer numIncomeGt100Rs2;
        /**
         * n-3月银行卡入账短信笔数
         */
        private Integer numIncomeGt100Rs3;
        /**
         * n-4月银行卡入账短信笔数
         */
        private Integer numIncomeGt100Rs4;
        /**
         * n月（申请当月）银行卡入账零钱短信笔数*（统计<100卢比）
         */
        private Integer numIncomeLt100Rs;
        /**
         * n-1月银行卡入账零钱短信笔数
         */
        private Integer numIncomeLt100Rs1;
        /**
         * n-2月银行卡入账零钱短信笔数
         */
        private Integer numIncomeLt100Rs2;
        /**
         * n-3月银行卡入账零钱短信笔数
         */
        private Integer numIncomeLt100Rs3;
        /**
         * n-4月银行卡入账零钱短信笔数
         */
        private Integer numIncomeLt100Rs4;
        /**
         * n月（申请当月）银行卡入账大额短信笔数*（统计>10000卢比）
         */
        private Integer numIncomeGt10000Rs;
        /**
         * n-1月银行卡入账大额短信笔数
         */
        private Integer numIncomeGt10000Rs1;
        /**
         * n-2月银行卡入账大额短信笔数
         */
        private Integer numIncomeGt10000Rs2;
        /**
         * n-3月银行卡入账大额短信笔数
         */
        private Integer numIncomeGt10000Rs3;
        /**
         * n-4月银行卡入账大额短信笔数
         */
        private Integer numIncomeGt10000Rs4;
        /**
         * n月（申请当月）银行卡入账短信金额（只统计大于100卢比）
         */
        private Double numIncomeGt100RsMoney;
        /**
         * n-1月银行卡入账短信金额
         */
        private Double numIncomeGt100RsMoney1;
        /**
         * n-2月银行卡入账短信金额
         */
        private Double numIncomeGt100RsMoney2;
        /**
         * n-3月银行卡入账短信金额
         */
        private Double numIncomeGt100RsMoney3;
        /**
         * n-4月银行卡入账短信金额
         */
        private Double numIncomeGt100RsMoney4;
        /**
         * n月（申请当月）银行卡入账短信余额均值（只统计大于100卢比）（只统计能取到的）
         */
        private Double numIncomeGt100RsBalAvg;
        /**
         * n-1月银行卡入账短信余额均值
         */
        private Double numIncomeGt100RsBalAvg1;
        /**
         * n-2月银行卡入账短信余额均值
         */
        private Double numIncomeGt100RsBalAvg2;
        /**
         * n-3月银行卡入账短信余额均值
         */
        private Double numIncomeGt100RsBalAvg3;
        /**
         * n-4月银行卡入账短信余额均值
         */
        private Double numIncomeGt100RsBalAvg4;
        /**
         * n月（申请当月）银行卡入账短信金额均值（只统计大于100卢比）
         */
        private Double numIncomeGt100RsMoneyAvg;
        /**
         * n-1月银行卡入账短信金额均值
         */
        private Double numIncomeGt100RsMoneyAvg1;
        /**
         * n-2月银行卡入账短信金额均值
         */
        private Double numIncomeGt100RsMoneyAvg2;
        /**
         * n-3月银行卡入账短信金额均值
         */
        private Double numIncomeGt100RsMoneyAvg3;
        /**
         * n-4月银行卡入账短信金额均值
         */
        private Double numIncomeGt100RsMoneyAvg4;
        /**
         * n月（申请当月）银行卡入账短信金额最大值（只统计大于100卢比）
         */
        private Double numIncomeGt100RsMoneyMax;
        /**
         * n-1月银行卡入账短信金额最大值
         */
        private Double numIncomeGt100RsMoneyMax1;
        /**
         * n-2月银行卡入账短信金额最大值
         */
        private Double numIncomeGt100RsMoneyMax2;
        /**
         * n-3月银行卡入账短信金额最大值
         */
        private Double numIncomeGt100RsMoneyMax3;
        /**
         * n-4月银行卡入账短信金额最大值
         */
        private Double numIncomeGt100RsMoneyMax4;
        /**
         * n月（申请当月）银行卡入账短信金额标准差（只统计大于100卢比）
         */
        private Double numIncomeGt100RsMoneySqrt;
        /**
         * n-1月银行卡入账短信金额标准差
         */
        private Double numIncomeGt100RsMoneySqrt1;
        /**
         * n-2月银行卡入账短信金额标准差
         */
        private Double numIncomeGt100RsMoneySqrt2;
        /**
         * n-3月银行卡入账短信金额标准差
         */
        private Double numIncomeGt100RsMoneySqrt3;
        /**
         * n-4月银行卡入账短信金额标准差
         */
        private Double numIncomeGt100RsMoneySqrt4;
        /**
         * n月（申请当月）银行卡入账短信金额极差（只统计大于100卢比）
         */
        private Double numIncomeGt100RsMoneyRange;
        /**
         * n-1月银行卡入账短信金额极差
         */
        private Double numIncomeGt100RsMoneyRange1;
        /**
         * n-2月银行卡入账短信金额极差
         */
        private Double numIncomeGt100RsMoneyRange2;
        /**
         * n-3月银行卡入账短信金额极差
         */
        private Double numIncomeGt100RsMoneyRange3;
        /**
         * n-4月银行卡入账短信金额极差
         */
        private Double numIncomeGt100RsMoneyRange4;
        /**
         * 近30天银行卡入账短信平均间隔天数（只统计大于100卢比）（例如近30天有3条入账短信，则取第一条和第三条的时间差除以2，如果只有1条或没有则为null）
         */
        private Double numIntervalAvg30;
        /**
         * 近60天银行卡入账短信平均间隔天数
         */
        private Double numIntervalAvg60;
        /**
         * 近90天银行卡入账短信平均间隔天数
         */
        private Double numIntervalAvg90;
        /**
         * n-1月与n-2月笔数差（只统计大于100卢比）
         */
        private Integer numIncomeGt100RsFrequency1;
        /**
         * n-2月与n-3月笔数差
         */
        private Integer numIncomeGt100RsFrequency2;
        /**
         * n-3月与n-4月笔数差
         */
        private Integer numIncomeGt100RsFrequency3;
        /**
         * n-1月与n-2月金额差
         */
        private Double numIncomeMoneyFrequency1;
        /**
         * n-2月与n-3月金额差
         */
        private Double numIncomeMoneyFrequency2;
        /**
         * n-3月与n-4月金额差
         */
        private Double numIncomeMoneyFrequency3;
        /**
         * n-1月与n-2月金额环比增长率（环比增长率=（本期的某个指标的值-上一期这个指标的值）/上一期这个指标的值*100%）
         */
        private Double numIncomeMoneyGrowth1;
        /**
         * n-2月与n-3月金额环比增长率
         */
        private Double numIncomeMoneyGrowth2;
        /**
         * n-3月与n-4月金额环比增长率
         */
        private Double numIncomeMoneyGrowth3;

    }
}
